package org.example.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.polo.Stock;

import java.util.List;

public interface StockMapper extends BaseMapper<Stock> {

    // update  db_stock set count = count - 1 where product_code=1001 and count >= 1
    @Update("update  db_stock set count = count - #{count}  where product_code=#{product_code} and count >= #{count}")
    int updateStocks(@Param("product_code") String productCode, @Param("count") int count);

//   select * from db_stock where product_code=1001 for update
    @Select("select * from db_stock where product_code=#{product_code} for update")
    List<Stock> selectUpdate(@Param("product_code") String productCode);
}
